<?php

namespace App\Http\Controllers;

use App\Models\Pictuer;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\PictuerRequest;
use App\Models\Tag;
use App\Models\PictuerTag;
use App\Models\ColorAverage;
class PictuersController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => ['index', 'show']]);
    }

  	public function index()
  	{
        
  	}

    public function show(Pictuer $pictuer, Request $request)
    {

        return view('pictuers.show', compact('pictuer'));
    }

	public function create(Pictuer $pictuer)
	{
		return view('pictuers.create_and_edit', compact('pictuer'));
	}

	public function store(PictuerRequest $request)
	{
		$pictuer = Pictuer::create($request->all());
		return redirect()->route('pictuers.show', $pictuer->id)->with('message', 'Created successfully.');
	}

	public function edit(Pictuer $pictuer)
	{
        $this->authorize('update', $pictuer);
		return view('pictuers.create_and_edit', compact('pictuer'));
	}

	public function update(PictuerRequest $request, Pictuer $pictuer)
	{
		$this->authorize('update', $pictuer);
		$pictuer->update($request->all());

		return redirect()->route('pictuers.show', $pictuer->id)->with('message', 'Updated successfully.');
	}

	public function destroy(Pictuer $pictuer)
	{
		$this->authorize('destroy', $pictuer);
		$pictuer->delete();

		return redirect()->route('pictuers.index')->with('message', 'Deleted successfully.');
	}
}
